import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../components/spin/spin.dart';
import '../../config/global_config.dart';
import '../../utils/screenutil/fit.dart';

class LoadMoreState extends StatelessWidget {
  LoadStatus descStatus;

  // 上拉加载更多状态
  // * [status] LoadStatus|状态值|必填
  LoadMoreState(LoadStatus status) : this.descStatus = status;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 640.f,
      height: 70.f,
      alignment: Alignment.center,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          descStatus == LoadStatus.loading
              ? Container(
                  margin: EdgeInsets.only(right: 10.f),
                  child: Spin(
                    size: 36.f,
                    color: GlobalConfig.assistColor,
                  ),
                )
              : SizedBox.shrink(),
          Text(
            _makeSureText(descStatus),
            style: TextStyle(
              fontSize: 22.f,
              color: GlobalConfig.assistColor,
            ),
          ),
        ],
      ),
    );
  }

  // 确认文本信息
  // * [mode] LoadStatus|上拉组件当前的状态
  String _makeSureText(LoadStatus mode) {
    String txt;
    switch (mode) {
      case LoadStatus.idle:
        txt = '上拉加载更多';
        break;
      case LoadStatus.loading:
        txt = '正在玩命加载';
        break;
      case LoadStatus.failed:
        txt = '加载失败';
        break;
      case LoadStatus.canLoading:
        txt = '请松开触碰加载更多';
        break;
      default:
        txt = '没有更多数据了';
    }
    return txt;
  }
}
